package com.zhengke.service.spxxgl;



import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.zhengke.pojo.GoodImages;
import com.zhengke.pojo.SysGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhengke.common.dao.CommonDao;
import com.zhengke.common.object.Result;
import com.zhengke.pojo.GoodsDetail;

/**  

* 创建时间：2019年12月26日 下午7:27:44 

* 项目名称：tvmallbs  

* @author 王东科

* @version 1.0     

* 文件名称：GoodsDetailServiceImpl.java  

* 类说明：  

*/
@Service
public class GoodsDetailServiceImpl implements GoodsDetailService {

	@Autowired
	private CommonDao dao;

	/**
	 * 查询商品信息
	 * @param goodsName
	 * @param gc1
	 * @param gc2
	 * @param gc3
	 * @param status
	 * @param brandName
	 * @param isNormal
	 * @param integralBuy
	 * @param pageNum
	 * @param size
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Result queryGoodsDetail(String goodsName,String gc1,String gc2,String gc3,String status,
			String brandName,String isNormal ,String integralBuy,int pageNum,int size) throws Exception {
		Map<String,String> param = new HashMap<String,String>();
		param.put("goodsName", goodsName);
		param.put("gc1", gc1);
		param.put("gc2", gc2);
		param.put("gc3", gc3);
		param.put("status", status);
		param.put("brandName", brandName);
		param.put("isNormal", isNormal);
		param.put("integralBuy", integralBuy);
		
		PageHelper.startPage(pageNum, size, true);
		
		List<GoodsDetail> list = (List<GoodsDetail>) dao.findForList("goodsDetailMapper.queryGoodsDetail", param);
		PageInfo<GoodsDetail> pageInfo = new PageInfo<GoodsDetail>(list);
		
		Result rs = new Result();
		rs.setCode("0");
		rs.setCount(pageInfo.getTotal());
		rs.setData(list);
		return rs;
	}

	/**
	 * 上架下架商品
	 * @param goodsDetail
	 * @throws Exception
	 */
	@Override
	public void updateStatus(GoodsDetail goodsDetail) throws Exception {
		Integer i = (Integer)dao.update("goodsDetailMapper.updateStatus",goodsDetail);
		if(i<0) {
			throw new Exception("修改失败");
		}
	}

	/**
	 * 删除商品信息
	 * @param goodsId
	 * @return
	 * @throws Exception
	 */
	@Override
	public Integer deleteGoodsDetail(Integer goodsId) throws Exception {
		Integer i = (Integer)dao.delete("goodsDetailMapper.deleteGoodsDetail", goodsId);
		return i;
	}

	/**
	 * 查询三级分类
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<SysGoods> querySys(int gcParentId) throws Exception {
		List<SysGoods> list = (List<SysGoods>) dao.findForList("goodsDetailMapper.queryParent", gcParentId);
		return list;
	}

	/**
	 * 通过doodsId查询商品图片信息
	 * @param goodsId
	 * @return
	 */
	@Override
	public List<GoodImages> queryImages(String goodsId) {
		List<GoodImages> imagesList = null;
		try {
			 imagesList = (List<GoodImages>) dao.findForList("goodsDetailMapper.queryImages",goodsId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return imagesList;
	}

	/**
	 * 修改商品图片
	 * @param goodImages
	 * @return
	 */
	@Override
	public int updateImages(GoodImages goodImages) {

		int i = 0;
		try {
			i = dao.update("goodsDetailMapper.updateImages",goodImages);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return i;
	}
}
